package cn.raven.controller;

import cn.raven.config.RestTempletConfig;
import cn.raven.entity.User;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class OrderController {
    @Autowired
    private RestTemplate restTemplate;

    @HystrixCommand(fallbackMethod = "downgrade")
    @GetMapping("/order/{id}")
    public User goUser(@PathVariable Long id){
        //调用user的接口
        String url = "http://user-server/user/"+id;
        return restTemplate.getForObject(url,User.class);
    }

    public User downgrade(@PathVariable Long id){
        //调用user的接口
        return User.builder().id(-1L).age("服务器繁忙,骚后重试！").build();
    }
}
